/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package services;

import dao.ProblemStatsJpaController;
import entities.Problem;
import entities.ProblemStats;
import entities.ProblemStats;
import java.util.List;
import vo.VOProblemStats;

public class ProblemStatsService {
    private static ProblemStatsJpaController psc;

    private ProblemStatsJpaController getJPAController()
    {
        if(psc == null)
            psc = new ProblemStatsJpaController();
        return psc;
    }

    public ProblemStats getProblemStats(Integer id)
    {
        psc = getJPAController();
        return psc.findProblemStats(id);
    }

    public boolean deleteProblemStats(ProblemStats c)
    {
        psc = getJPAController();
        try
        {
            psc.destroy(c.getIdProblemStats());
            return true;
        }
        catch (Exception e)
        {
            return false;
        }
    }

    public ProblemStats getStatsByProblem(Problem p)
    {
        psc = getJPAController();
        try
        {
            return psc.findByProblem(p);
        }
        catch (Exception e)
        {
            return null;
        }
    }

    public List<ProblemStats> getAllStats()
    {
        psc = getJPAController();
        try
        {
            return psc.findAll();
        } catch (Exception e)
        {
            return null;
        }
    }
}
